package cn.chinaflame.pagodas.repository;

import cn.chinaflame.pagodas.entity.YwSession;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author bm
 * 2018年1月15日 下午7:59:50
 */
public interface YwSessionRepository extends JpaRepository<YwSession, String> {

    @Modifying
    @Query(value = "delete from YwSession c where c.userid = ?1")
    public int deleteByUserid(String userid);

    /*@Query("select c from YwSession c where c.userid = ?1")
    public YwSession findByUserid(String userid);*/
    List<YwSession> findByUserid(String userid);

    @Query("select c from YwSession c where c.sessionid = ?1 and c.projectId = ?2")
    public YwSession findBySessionidAndProjectId(String sessionid, String projectId);

    @Modifying
    @Query(value = "update YwSession c set c.updateTimestamp = ?1 where c.sessionid = ?2 and c.projectId = ?3")
    public int updateByUpdateTimestamp(long updateTimestamp, String sessionid, String projectId);

}
